//
//  ChartCategoryDetailView.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 08.04.25.
//

import SwiftUI

struct ChartCategoryDetailView: View {
    
    @State var date: Date
    @State var category: AccountingCategory
    @State var dateSelectType: DateSelectType
    
    var body: some View {
        VStack {
            ZStack {
                HStack {
                    KoiBackButton()
                    Text(category.name.orEmpty)
                        .font(.system(size: 14))
                        .foregroundColor(Color.koiColorTitle)
                    Spacer()
                }
                HStack {
                    KoiTabBar<DateSelectType>(selection: $dateSelectType, items: [
                        TabBarItem(tab: DateSelectType.week, name: DateSelectType.week.typeName()),
                        TabBarItem(tab: DateSelectType.month, name: DateSelectType.month.typeName()),
                        TabBarItem(tab: DateSelectType.year, name: DateSelectType.year.typeName()),
                    ]).padding(.horizontal, 20)
                }
            }
            TabView(selection: $dateSelectType) {
                ChartCategoryDetailDateWeekView(
                    date: date, category: category).tag(DateSelectType.week)
                ChartCategoryDetailDateMonthView(
                    date: date, category: category).tag(DateSelectType.month)
                ChartCategoryDetailDateYearView(
                    date: date, category: category).tag(DateSelectType.year)
            }.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
        }
        .background(Color.koiColorBackground)
        .navigationBarBackButtonHidden(true)
    }
}

#Preview {
    ChartCategoryDetailView(date: Date(), category: AccountingCategory(), dateSelectType: .week)
}
